In this lab, I completed the Task A stunt of flipping the car. This involved updating the code for the PID to use the ToF extrapolation function and having a small state machine to control when the car should flip based on the distance to the wall.
Stunt Task
This stunt involved:
Starting < 4m from the wall at the start line
Driving forward until reaching the sticky mat
Flipping
Driving back towards the start line
I first set the PWM value of both motors to 255 to drive forward quickly. Then I had the robot wait .9 seconds before reacting to ToF values. This avoided reacting to the initial noisy ToF values due to the long distance that sometimes led to shorter ToF being recorded.
To avoid having false positives, I have the loop confirm that the ToF value, or extrapolated value, was less than the distance to the wall 3 state machine cycle times before moving to the next state to flip.
Here is my state machine code:
The distance to flip was set at 175 millimeters due to the ToF calibration errors and made the robot flip in the center of the sticky mat.
Once it flipped, the robot waited 1 second to settle after landing and then drove back to the start line as fast as possible.
Here is the rest of my stunt code:
The image below is data I recorded during testing to make sure the state machine was working correctly. This is the expected data during the trial runs and used the front ToF sensor. The front sensor was reading correctly at low speeds that were not fast enough to have the robot flip, but had issues recording data when running fast to have the robot flip as can be seen in the data below.
Here are three trial videos: with the data graphs with IMU, ToF, extrapolated ToF, and motor values with time stamps:
Trial 1:
Trial 2:
Trial 3:
Trial Data
For all the trials, the ToF sensor was giving me issues with the data. The data was not consistent and would often give me a value of 0 when the robot was moving fast.
This was due to the sensor not being able to read the distance to the wall when the robot was moving fast, likely due to a hardware connection as the side sensor was working fine during fast speeds.
The graph below shows the data from the front ToF sensor and the extrapolated data from the trials which was the same for all three trials.